package com.wangjiyuan.shiwupai.mine.activitiy;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.view.View;

import com.wangjiyuan.shiwupai.R;
import com.wangjiyuan.shiwupai.adapter.MyOrderViewPagerAdapter;
import com.wangjiyuan.shiwupai.base.BaseActivity;
import com.wangjiyuan.shiwupai.mine.fragment.ItemMyOrderDespatchedFragment;
import com.wangjiyuan.shiwupai.mine.fragment.ItemMyOrderObligationFragment;
import com.wangjiyuan.shiwupai.mine.fragment.ItemMyOrderPaidFragment;

import java.util.ArrayList;
import java.util.List;

public class MyOrderActivity extends BaseActivity {

    private Toolbar toolBar_myOrder_back;
    private List<Fragment> fragmentList;
    private MyOrderViewPagerAdapter myOrderViewPagerAdapter;
    private ViewPager vp_myOrder_item;
    private TabLayout tab_myOrder_item;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_order);

        initToolBar();
        initData();
        initViewPager();
        initTabLayout();
    }

    private void initTabLayout() {
        tab_myOrder_item = (TabLayout) findViewById(R.id.tab_myOrder_item);
        tab_myOrder_item.setupWithViewPager(vp_myOrder_item);
    }

    private void initViewPager() {
        vp_myOrder_item = (ViewPager) findViewById(R.id.vp_myOrder_item);

        FragmentManager fragmentManager = getSupportFragmentManager();
        myOrderViewPagerAdapter = new MyOrderViewPagerAdapter(fragmentManager, fragmentList);
        vp_myOrder_item.setAdapter(myOrderViewPagerAdapter);
    }

    private void initData() {
        ItemMyOrderObligationFragment obligationFragment = new ItemMyOrderObligationFragment();
        ItemMyOrderDespatchedFragment despatchedFragment = new ItemMyOrderDespatchedFragment();
        ItemMyOrderPaidFragment paidFragment = new ItemMyOrderPaidFragment();
        fragmentList = new ArrayList<>();
        fragmentList.add(obligationFragment);
        fragmentList.add(despatchedFragment);
        fragmentList.add(paidFragment);
    }

    private void initToolBar() {
        toolBar_myOrder_back = (Toolbar) findViewById(R.id.toolBar_myOrder_back);
        toolBar_myOrder_back.setTitle("我的订单");
        toolBar_myOrder_back.setNavigationIcon(R.mipmap.icon_back_black);
        toolBar_myOrder_back.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }
}
